------------------------------------------------- AmigaCOMAL-COMMON BASIC KEYWORDS! ------------------------------------------------- Assembled from AmigaCOMAL floppy disk Version 2.0 {Credits: Comal Today, USA} 15:11 04.10.2025 ------------------------------------------------- Edited and assambled: by www.lived.ch ------------------------------------------------- NOTE 1: COMMON BASIC KEYWORDS are not part of any Comal Package. They are built-in and available directly, without involving the USE {Package} to link {connected} the package with to source code. NOTE 2: These are AmigaCOMAL v2.0 Keywords, but i strongly assume not much was change in that area and it should be compatible. Package Keywords are downloadable as a separate file for AmigaCOMAL v1.4. Check www.lived.ch ------------------------------------------------- In case you want to start with AmigaCOMAL coding, this is pure gold! ------------------------------------------------- 0010 REPEAT 0020 INPUT "number (0 to stop): ": num 0030 IF abs(num)<>num THEN PRINT "that is negative" 0040 absnum:=abs(num) 0050 PRINT "absolute value of";num;"is";absnum 0060 UNTIL num=0 0070 END "Done" 0010 PRINT "ACS is Arccosine." 0020 PRINT "Sorry, but I can't get my example to work." 0030 // print acs(9) 0010 PRINT "ALLOCATE(new@) ..." 0020 PRINT "See Chapter 3.6 in the manual." 0010 word1$:="captain"; word2$:="comal" 0020 REPEAT 0030 PRINT "What letter appears in both" 0040 PRINT word1$;"&";word2$ 0050 INPUT guess$ 0060 UNTIL (guess$ IN word1$) AND (guess$ IN word2$) 0070 END "Done" 0010 PRINT "AND THEN is not part of Common COMAL." 0020 PRINT "and is not included in AmigaCOMAL." 0010 filename$:="visitor.dat" 0020 OPEN FILE 2,filename$,APPEND 0030 LOOP 0040 INPUT "Visitor Name ("" to end): ": name$ 0050 EXIT WHEN name$="" 0060 WRITE FILE 2: name$ 0070 ENDLOOP 0080 CLOSE FILE 2 0090 END "Done" 0010 page 0020 PRINT "AmigaCOMAL was started from";argarray$(-1) 0030 PRINT "The name used was";argarray$(0) 0040 IF argnum>0 THEN 0050 PRINT "These parameters were passed:" 0060 FOR x:=1 TO argnum DO 0070 PRINT x;argarray$(x) 0080 ENDFOR x 0090 ELSE 0100 PRINT "There were no parameters passed." 0110 ENDIF 0120 END "Done" 0010 page 0020 IF argnum>0 THEN 0030 PRINT "You passed";argnum;"parameters." 0040 ELSE 0050 PRINT "No paramenters were passed to COMAL." 0060 ENDIF 0010 PRINT "ASN is Arcsine." 0020 PRINT "Sorry, but I can't get my example to work." 0030 // print asn(9) 0010 // using AT without specifying row/col 0020 // giving protected input fields! 0030 page 0040 INPUT AT 0,0,2: "Enter the current hour: ": hour$ 0050 PRINT hour$;"O'Clock" 0060 PRINT "Next enter (digits only) your" 0070 ssn$:=spc$(9) //space fill init 0080 INPUT AT 0,0,9: "Social Security Num: ": ssn$(1:9) 0090 PRINT ssn$(1:3),"-",ssn$(4:5),"-",ssn$(6:9) 0100 INPUT AT 0,0,1: "Yes or No? ": reply$; 0110 CASE reply$ OF 0120 WHEN "y","Y" 0130 PRINT "Yes" 0140 WHEN "n","N" 0150 PRINT "No" 0160 OTHERWISE 0170 PRINT "Error" 0180 ENDCASE 0190 END "Done" 0010 LOOP 0020 INPUT "Number (0 to end): ": num 0030 EXIT WHEN num=0 0040 PRINT "arctangent of";num;"is";atn(num) 0050 ENDLOOP 0060 END "Done" 0010 PRINT "AUTO is used to start" 0020 PRINT "automatic line numbering" 0030 PRINT "while entering a program." 0010 USE SYSTEM 0020 LOOP 5 TIMES 0030 num1:=rnd(1,255); num2:=rnd(1,255) 0040 PRINT bin$(num1);"BITAND";bin$(num2) 0050 PRINT bin$(num1 BITAND num2) 0060 PRINT 0070 ENDLOOP 0080 END "Done" 0010 //chart of BITAND BITOR BITXOR operations 0020 USE SYSTEM 0030 ZONE 4 0040 page 0050 PRINT " A B || AND OR XOR" 0060 FOR a:=%0 TO %11 DO 0070 FOR b:=%0 TO %11 DO 0080 PRINT bin$(a);bin$(b);"||"; 0090 PRINT bin$(a BITAND b); 0100 PRINT bin$(a BITOR b); 0110 PRINT bin$(a BITXOR b) 0120 ENDFOR b 0130 ENDFOR a 0140 END "Done" 0010 //chart of BITAND BITOR BITXOR operations 0020 DIM binary$(0:3) OF 2 0030 binary$(%0):="00"; binary$(%1):="01" 0040 binary$(%10):="10"; binary$(%11):="11" 0050 page 0060 PRINT " A B ||AND OR XOR" 0070 FOR a:=%0 TO %11 DO 0080 FOR b:=%0 TO %11 DO 0090 PRINT binary$(a);binary$(b);"||"; 0100 PRINT binary$(a BITAND b); 0110 PRINT binary$(a BITOR b); 0120 PRINT binary$(a BITXOR b) 0130 ENDFOR b 0140 ENDFOR a 0150 END "Done" 0010 PRINT "BYE is used to quit COMAL." 0020 PRINT "You also may use the drop down MENU" 0030 PRINT "or click on the close window gadget." 0010 REPEAT 0020 INPUT "How many did you eat? ": num 0030 UNTIL num>=0 0040 CASE num OF 0050 WHEN 0 0060 PRINT "You might starve." 0070 WHEN 1 0080 PRINT "Just an appetizer." 0090 WHEN 2,3 0100 PRINT "Not bad. I ate about that many." 0110 WHEN 4,5,6 0120 PRINT "Big eater, huh." 0130 OTHERWISE 0140 PRINT "I won't pay the bill." 0150 ENDCASE 0160 END "Done" 0010 PRINT "CAT is converted to DIR." 0020 PRINT "It gives a disk catalog." 0030 DIR // this was typed in as CAT 0010 PRINT "CD is converted to CHDIR for you." 0010 page 0020 PRINT "E - Edit data" 0030 PRINT "I - Input new data" 0040 PRINT "P - Printout data" 0050 PRINT "Q - Quit" 0060 LOOP 0070 INPUT "Your choice? ": reply$ 0080 CASE reply$ OF 0090 WHEN "e","E" 0100 CHAIN "editdata" 0110 WHEN "i","I" 0120 CHAIN "indata" 0130 WHEN "p","P" 0140 CHAIN "printout" 0150 WHEN "q","Q" 0160 END "Done" 0170 OTHERWISE 0180 PRINT "Enter E, I, P, or Q" 0190 ENDCASE 0200 ENDLOOP 0010 PRINT "CHANGE is an editing command." 0020 PRINT "It will search a program in memory" 0030 PRINT "and replace part of a program line" 0040 PRINT "with a new part." 0050 PRINT "With this program try this:" 0060 PRINT "CHANGE ""program"",""setup""" 0070 PRINT "Use + to repeat the command" 0080 PRINT "after the first line. Hit on the" 0090 PRINT "line first if you wish to make the change." 0100 END "Done" 0010 page 0020 current$:=dir$ //remember current directory 0030 CHDIR "/" // go to root directory 0040 PRINT "This is the contents of the ROOT directory:" 0050 DIR 0060 CHDIR current$ 0070 PRINT "Back to your original directory:" 0080 DIR 0090 END "Done" 0010 FOR x:=ord("a") TO ord("g") DO 0020 PRINT x;chr$(x) 0030 ENDFOR x 0040 END "Done" 0010 CLOSE // make sure all files are closed 0020 outfile:=freefile; player$:="Amy"; hiscore:=58 0030 PRINT player$;"has the high score of";hiscore 0040 OPEN FILE outfile,"scores.dat",WRITE 0050 WRITE FILE outfile: player$,hiscore 0060 CLOSE FILE outfile 0070 END "Done" 0010 test:=1 // <<---main program variable 0020 PRINT "Main TEST is";test 0030 sample 0040 PRINT "Main TEST still is";test 0050 END "Done" 0060 PROC sample CLOSED 0070 test:=2 // <<---no conflict with main 0080 PRINT "Inside SAMPLE. TEST here is";test 0090 ENDPROC 0010 page 0020 PRINT "COPY will copy a file. If an" 0030 PRINT "icon file exists for the file, it" 0040 PRINT "too will be copied." 0050 END "Done" 0010 LOOP 5 TIMES 0020 angle:=rnd(1,100) 0030 PRINT "Cosine of";angle;"is";cos(angle) 0040 ENDLOOP 0050 END "Done" 0010 page 0020 PRINT "CREATE will create a random acces" 0030 PRINT "file with the number of blank records" 0040 PRINT "you specify. Each record will be of the" 0050 PRINT "size you specified." 0060 END "Done" 0010 page 0020 PRINT "Enter text" 0030 INPUT text$; // ; prevents carriage return 0040 PRINT "<",curcol,">" 0050 END "Done" 0010 page 0020 FOR rows:=1 TO 10 DO PRINT "line";currow 0030 END "Done" 0010 page 0020 PRINT "Hit any keys. Hit X to eXit" 0030 LOOP 0040 hit$:=key$ 0050 EXIT WHEN hit$ IN "Xx" 0060 CURSOR 5,5 0070 PRINT hit$ 0080 ENDLOOP 0090 END "Done" 0010 RESTORE NAMES 0020 REPEAT 0030 READ age,name$ 0040 PRINT name$;"is";age;"years old." 0050 UNTIL eod 0060 END "Done" 0070 // 0080 INFO: 0090 DATA "skip this data item" 0100 NAMES: 0110 DATA 28,"Waldo",42,"Hilda",57 0120 DATA "Joe ""The Cat"" Baker",6 0130 DATA "Tiny" 0010 page 0016 today$:=date$ 0020 year$:=today$(3:4) 0030 month$:=today$(6:7) 0040 day$:=today$(9:10) 0050 PRINT month$,"/",day$,"/",year$ 0060 END "Done" 0010 page 0020 PRINT "DEALLOCATE ... see Chapter 3.6" 0030 END "Done" 0010 page 0020 PRINT "DEL is a command to delete" 0030 PRINT "lines in the program in memory." 0040 PRINT "You may delete ranges of lines" 0050 PRINT "by specifying the starting and" 0060 PRINT "ending line numbers, or by" 0070 PRINT "using the procedure or function" 0080 PRINT "name." 0090 END "Done" 0010 page 0020 PRINT "Delete files program." 0030 PRINT "For";dir$ 0040 LOOP 0050 PRINT "Filename? (Q to Quit)" 0060 INPUT filename$; 0070 EXIT WHEN filename$ IN "Qq" 0080 DELETE filename$ 0090 PRINT "" //even if not there 0100 ENDLOOP 0110 END "Done" 0010 page 0020 INPUT "Low limit? ": lo 0030 INPUT "High limit?": hi 0040 DIM score(lo:hi) 0050 LOOP 0060 INPUT "Enter score (0=stop): ": num 0070 EXIT WHEN num=0 0080 IF num>=lo AND num<=hi THEN 0090 score(num):+1 0100 ELSE 0110 PRINT "Out of range." 0120 ENDIF 0130 ENDLOOP 0140 FOR num:=lo TO hi DO 0150 IF score(num)>0 THEN 0160 PRINT "score";num;"occurs";score(num);"times." 0170 ENDIF 0180 ENDFOR num 0190 END "Done" 0010 page 0020 PRINT "Directory for";dir$ 0030 DIR 0040 END "Done" 0010 page 0020 PRINT "DISCARD is a command that" 0030 PRINT "removes packages from memory." 0040 END "Done" 0010 page 0020 PRINT "DISPLAY lists the program in" 0030 PRINT "memory without line numbers." 0040 PRINT "Include a file name and it" 0050 PRINT "will be displayed to disk." 0060 END "Done" 0010 page 0020 PRINT "Enter 0 as 1st number to stop." 0030 LOOP 0040 INPUT "Number: ": num1 0050 EXIT WHEN num1=0 0060 INPUT "Divided by: ": num2 0070 PRINT num1;"divided by";num2;"is"; 0080 PRINT num1 DIV num2; 0090 IF num1 MOD num2 THEN PRINT "REM";num1 MOD num2; 0100 PRINT //carriage return 0110 ENDLOOP 0120 END "Done" 0010 DIM reply$ OF 1 // limit to one character 0020 REPEAT 0030 PRINT "Enter Capital letter (* to stop)" 0040 INPUT reply$; 0050 IF reply$ IN "AEIOU" THEN 0060 PRINT "vowel" 0070 ELIF reply$ IN "BCDFGHJKLMNPQRSTVWXYZ" THEN 0080 PRINT "consonant" 0090 ELIF reply$ IN "0123456789" THEN 0100 PRINT "digit" 0110 ELSE 0120 PRINT "other" 0130 ENDIF 0140 UNTIL reply$="*" 0150 END "Done" 0010 DIM choice$ OF 1 0020 REPEAT 0030 INPUT "Yes or No?": choice$ 0040 IF choice$ IN "Yy" THEN 0050 PRINT "Yes it is." 0060 ELIF choice$ IN "Nn" THEN 0070 PRINT "Nope." 0080 ELSE 0090 PRINT "Try again." 0100 ENDIF 0110 UNTIL choice$ IN "YyNn" 0010 PRINT "Running program." 0020 END "Done" 0030 PRINT "This line does not print" 0010 page 0020 DIM choice$ OF 1 // limit to 1 char 0030 LOOP 0040 INPUT "Your choice (A,S,H,Q): ": choice$; 0050 CASE choice$ OF 0060 WHEN "A","a" 0070 PRINT "Add" 0080 WHEN "S","s" 0090 PRINT "Subtract" 0100 WHEN "H","h" 0110 PRINT "Help" 0120 PRINT "A=Add, S=Subtract, Q=Quit" 0130 WHEN "Q","q" 0140 EXIT 0150 OTHERWISE 0160 PRINT "Try again." 0170 ENDCASE 0180 ENDLOOP 0190 END "Done" 0010 page 0020 FOR num1:=1 TO 3 DO 0030 FOR num2:=3 TO 4 DO 0040 PRINT num1;"plus";num2;"is";num1+num2 0050 ENDFOR num2 0060 ENDFOR num1 0070 END "Done" 0010 page 0020 LOOP 0030 INPUT "What number (0=stop): ": number 0040 EXIT WHEN number=0 0050 IF even(number) THEN 0060 PRINT number;"is an even number." 0070 ELSE 0080 PRINT number;"is an odd number." 0090 ENDIF 0100 ENDLOOP 0110 END "Done" 0120 // 0130 FUNC even(num) 0140 IF num MOD 2 THEN 0150 RETURN false 0160 ELSE 0170 RETURN true 0180 ENDIF 0190 ENDFUNC even 0010 page 0020 number:=rnd(1,10) //random integer between 1 and 10 0030 trys:=0; lows:=0; highs:=0 0040 REPEAT 0050 INPUT "Your guess: ": guess; 0060 trys:+1 // increment trys counter 0070 IF guessnumber THEN 0110 PRINT "too high." 0120 highs:+1 // increment highs count 0130 ENDIF 0140 UNTIL guess=number 0150 PRINT "Yes." 0160 PRINT trys;"guesses." 0170 PRINT "Guesses too low: ";lows 0180 PRINT "Guesses too high:";highs 0190 END "Done" 0010 page 0020 errors:=0 0030 PRINT "Practice Adding" 0040 LOOP 0050 num1:=rnd(1,10); num2:=rnd(1,10) 0060 PRINT num1;"+";num2; 0070 INPUT answer; 0080 IF answer=num1+num2 THEN 0090 PRINT "Yes" 0100 ELSE 0110 PRINT "No" 0120 errors:+1 0130 EXIT WHEN errors>1 0140 PRINT "We allow only one error." 0150 ENDIF 0160 PRINT "Here is another question:" 0170 ENDLOOP 0180 END "Done" 0010 page 0020 INPUT "Hi. What is your name? ": name$ 0030 welcome(name$) 0040 END "Done" 0050 // 0060 PROC welcome(n$) 0070 PRINT "Welcome to COMAL,";n$ 0080 PRINT "Hope you enjoy it." 0090 ENDPROC welcome 0010 page 0020 PRINT "ENDRECORD ... see Chapter 3.3" 0030 PRINT "for explanation." 0040 END "Done" 0010 LOOP 0020 TRAP // catch input error in next line 0030 INPUT "Enter a number (0=stop): ": number 0040 EXIT WHEN number=0 0050 HANDLER 0060 PRINT 0070 PRINT "input error. The number 0 will be used." 0080 ENDTRAP 0090 PRINT "Your number is";number 0100 ENDLOOP 0110 END "Done" 0010 missed:=false; count:=0 0020 WHILE NOT missed DO 0030 count:+1 // increment count 0040 num1:=rnd(1,9); num2:=rnd(1,9) 0050 PRINT count,"> What is";num1;"+";num2; 0060 INPUT number; 0070 IF number=num1+num2 THEN 0080 PRINT "Yes" 0090 ELSE 0100 PRINT "Ooops" 0110 missed:=true 0120 ENDIF 0130 ENDWHILE 0140 PRINT "Answers right up to problem";count 0150 END "Done" 0010 page 0020 PRINT "ENTER is the command used to" 0030 PRINT "retrieve a program that was" 0040 PRINT "stored in ASCII form. LIST" 0050 PRINT "is the command that stores" 0060 PRINT "a program in ASCII form." 0070 END "Done" 0010 page 0020 count:=0 0030 WHILE NOT eod DO 0040 READ dummy 0050 count:+1 // increment count 0060 ENDWHILE 0070 PRINT "There are";count;"numbers." 0080 RESTORE // reset next data pointer to start 0090 WHILE NOT eod DO 0100 READ number 0110 PRINT number; 0120 ENDWHILE 0130 END "Done" 0140 DATA 1,2,5,99 0150 DATA 78 0010 page 0020 PRINT "Reading VISTOR file..." 0030 DIM name$ OF 100 0040 OPEN FILE 2,"visitor.dat",READ 0050 WHILE NOT eof(2) DO 0060 READ FILE 2: name$ 0070 PRINT name$ 0080 ENDWHILE 0090 CLOSE 0100 END "Done" 0010 page 0020 LOOP 0030 TRAP 0040 INPUT "Enter a number: ": number 0050 IF number<-99 THEN REPORT 9999 0060 IF number>99 THEN REPORT 8888 0070 EXIT // no error 0080 HANDLER 0090 PRINT // go to next line 0100 CASE err OF 0110 WHEN 104 0120 PRINT "A number is expected." 0130 WHEN 8888 0140 PRINT "The number was too big!" 0150 PRINT "We have a limited range for this test." 0160 WHEN 9999 0170 PRINT "The number was too negative!" 0180 PRINT "It does not pay to be too negative." 0190 OTHERWISE 0200 REPORT // can't handle this error 0210 ENDCASE 0220 ENDTRAP 0230 ENDLOOP 0240 PRINT "It is";number 0250 END "Done" 0010 page 0020 TRAP 0030 OPEN FILE 1,"visitor.dat",READ 0040 OPEN FILE 2,"nofile.here",READ 0050 HANDLER 0060 CLOSE 0070 PRINT "Error with file";errfile 0080 ENDTRAP 0090 END "Done" 0010 page 0020 FOR x:=100 TO 999 DO 0030 IF len(errtext$(x))>6 THEN //not empty message 0040 PRINT x;errtext$(x)(7:) //7th char to end 0050 ENDIF 0060 ENDFOR x 0070 END "Done" 0010 page 0020 TRAP ESC- // trap BREAK 0030 OPEN FILE 3,"zzjunk.dat",WRITE 0040 PRINT "Sample file open." 0050 PRINT "Break program now." 0060 LOOP 0070 WAIT 0080 IF esc THEN EXIT 0090 PRINT "Press AMIGA + S to Stop a program." 0100 ENDLOOP 0110 PRINT "*** BREAK ***" 0120 PRINT "Closing files first" 0130 CLOSE 0140 TRAP ESC+ 0150 END "Done" 0010 page //a built in procedure 0020 PRINT "Demo of EXEC." 0030 PRINT "EXEC is used to call a procedure." 0040 PRINT "However, it is optional and not even listed" 0050 PRINT "unless you issue the SETEXEC+ command." 0060 PRINT 0070 FOR temp:=1 TO 3 DO 0080 INPUT "Word:": word$; 0090 INPUT "Count:": count 0100 demo(count,word$) //call the DEMO procedure 0110 ENDFOR temp 0120 END "Done" 0130 // 0140 PROC demo(n,t$) CLOSED 0150 PRINT n*t$ 0160 ENDPROC demo 0010 page 0020 LOOP 0030 TRAP 0040 INPUT "Enter a number (1-9):": num 0050 EXIT WHEN num>=1 AND num<=9 0060 PRINT "The number must be only one digit" 0070 HANDLER 0080 PRINT 0090 PRINT "Please enter a one digit number" 0100 ENDTRAP 0110 ENDLOOP 0120 PRINT "Number was";num 0130 END "Done" 0010 page 0020 PRINT "EXP practice." 0030 LOOP 0040 INPUT "Power (0=stop): ": num 0050 EXIT WHEN num=0 0060 PRINT "Answer is";exp(num) 0070 ENDLOOP 0080 END "Done" 0010 page 0020 PRINT "EXPORT ... see some of the" 0030 PRINT "packages in the directory" 0040 PRINT "named packages (example is" 0050 PRINT "TYPE)." 0060 END "Done" 0010 welcome 0020 PROC welcome EXTERNAL "welcome" 0030 END "Done" 0010 page 0020 LOOP 5 TIMES 0030 num:=rnd(1,99) 0040 IF even(num) THEN 0050 PRINT num;"is even." 0060 ELSE 0070 PRINT num;"is odd." 0080 ENDIF 0090 ENDLOOP 0100 END "Done" 0110 // 0120 FUNC even(n) CLOSED 0130 IF n MOD 2 THEN 0140 RETURN false 0150 ELSE 0160 RETURN true 0170 ENDIF 0180 ENDFUNC even 0010 page 0020 PRINT "FIELD ... see Chapter 3.3." 0030 END "Done" 0010 page 0020 PRINT "FILE is part of the commands:" 0030 PRINT "OPEN FILE" 0040 PRINT "CLOSE FILE" 0050 PRINT "WRITE FILE" 0060 PRINT "READ FILE" 0070 PRINT "INPUT FILE" 0080 PRINT "PRINT FILE" 0090 END "Done" 0010 page 0020 PRINT "FIND is an editing command" 0030 PRINT "that will find a part of a" 0040 PRINT "program line in the program" 0050 PRINT "currently in memory." 0060 END "Done" 0010 page 0020 PRINT "FLOAT is a function that will" 0030 PRINT "return a floating point" 0040 PRINT "representation of a number." 0050 PRINT "You can pass it an integer and" 0060 PRINT "it returns it as floating point." 0070 END "Done" 0010 page 0020 INPUT "How many scores: ": max 0030 total:=0 0040 FOR temp:=1 TO max DO 0050 INPUT "Score: ": score 0060 total:+score 0070 ENDFOR temp 0080 PRINT "Total was";total 0090 PRINT "Average was";total/max 0100 END "Done" 0010 page 0020 PRINT "How is the memory doing?" 0030 PRINT "Free memory available to" 0040 PRINT "COMAL now is";free 0050 END "Done" 0010 page 0020 infile:=freefile // get a file number that is not in use 0030 OPEN FILE infile,"visitor.dat",READ 0040 WHILE NOT eof(infile) DO 0050 INPUT FILE infile: name$ 0060 PRINT name$ 0070 ENDWHILE 0080 CLOSE 0090 END "Done" 0010 page 0020 DIM type$(false:true) OF 4 0030 type$(false):="Odd" 0040 type$(true):="Even" 0050 LOOP 0060 INPUT "Number (0=stop): ": num; 0070 EXIT WHEN num=0 0080 PRINT type$(even(num)) 0090 ENDLOOP 0100 END "Done" 0110 // 0120 FUNC even(n) CLOSED 0130 IF n MOD 2 THEN 0140 RETURN false 0150 ELSE 0160 RETURN true 0170 ENDIF 0180 ENDFUNC even 0005 page 0010 type("visitor.dat") 0020 END "Done" 0030 // 0040 PROC type(name$) CLOSED 0050 TRAP 0060 f:=freefile 0070 OPEN FILE f,name$,READ 0080 WHILE NOT eof(f) DO 0090 PRINT get$(f,1), 0100 ENDWHILE 0110 CLOSE FILE f 0120 HANDLER 0130 PRINT "Error." 0140 ENDTRAP 0150 ENDPROC type 0010 GLOBAL player$ 0020 page 0030 INPUT "Enter your name: ": player$ 0040 INPUT "Enter your score:": score 0050 questions:=25 0060 evaluate(score,questions) 0070 END "Done" 0080 // 0090 PROC evaluate(s,q) CLOSED 0100 PRINT player$,","; // global so can use it here 0110 PRINT "You got";s;"points." 0120 PRINT "There were";q;"questions." 0130 PRINT "That is about";s DIV q;"per question." 0140 ENDPROC evaluate 0010 page 0020 LOOP 0030 INPUT "Next item name (0=stop): ": name$ 0040 IF name$="0" THEN GOTO QUIT 0050 PRINT name$ 0060 ENDLOOP 0070 QUIT: 0080 END "I quit. Why not just use EXIT?" 0010 page 0020 PRINT "Factorial practice" 0030 LOOP 0040 INPUT "Number (0=stop): ": num 0050 EXIT WHEN num=0 0060 PRINT factorial(num) 0070 ENDLOOP 0080 END "Done" 0090 // 0100 FUNC factorial(number) CLOSED 0110 TRAP // catch numbers too large overflow 0120 RETURN fac(number) 0130 HANDLER 0140 RETURN 1E+194 // a very large number 0150 ENDTRAP 0160 // 0170 FUNC fac(number) // nested function 0180 IF number=0 THEN 0190 RETURN 1 0200 ELSE 0210 RETURN fac(number-1)*number //recursive call 0220 ENDIF 0230 ENDFUNC fac 0240 ENDFUNC factorial 0010 page 0020 total:=0; count:=0 //initialize 0030 LOOP 0040 INPUT "Number (0=stop): ": num 0050 EXIT WHEN num=0 0060 IF num>0 THEN 0070 count:+1 // increment counter 0080 total:+num //add number to total 0090 PRINT "That makes the total";total 0100 ELSE 0110 PRINT "Negative numbers don't count." 0120 ENDIF 0130 ENDLOOP 0140 avg:=total DIV count 0150 PRINT "The total for";count;"numbers was";total 0160 PRINT "That means the average was"; 0170 IF total/count<>avg THEN PRINT "about"; 0180 PRINT avg 0190 END "Done" 0010 page 0020 my'name$:="Calvin" 0030 PRINT "Hi, I'm";my'name$ 0040 INPUT "What is your name? ": name$ 0050 printout(my'name$) // pass my name to proc 0060 PRINT "Back in the main program." 0070 PRINT "Now your name is";name$ 0080 PRINT "But mine is still";my'name$ 0090 END "Done" 0100 // 0110 PROC printout(my'name$) CLOSED 0120 IMPORT name$ 0130 PRINT "This is just an example";name$ 0140 PRINT "So let's change your name." 0150 name$:="Mud"; my'name$:="Amiga" 0160 PRINT "While we are inside here," 0170 PRINT "Your name is";name$ 0180 PRINT "My name is";my'name$ 0190 ENDPROC printout 0010 page 0020 DIM hit$ OF 5, letter$ OF 1 0030 count:=0; a:=ord("a"); z:=ord("z") 0040 PRINT "I will randomly pick and print" 0050 PRINT "letters until I hit one of" 0060 PRINT "5 letters you choose." 0070 REPEAT 0080 INPUT "Enter your 5 hit letters:": hit$ 0090 UNTIL len(hit$)=5 0100 PRINT "Your HIT letters are:" 0110 FOR x:=1 TO 5 DO PRINT hit$(x:x) //substring 0120 PRINT "Here we go..." 0130 REPEAT 0140 letter$:=chr$(rnd(a,z)) // a and z are set to ascii values already 0150 PRINT letter$, 0160 count:+1 0170 UNTIL (letter$ IN hit$) OR (count>100) 0180 PRINT //carriage return 0190 IF count>100 THEN 0200 PRINT "Your hit letters must not be" 0210 PRINT "unshifted letters." 0220 ELSE 0230 PRINT "A hit! After";count;"letters." 0240 ENDIF 0250 END "Done" 0010 page 0020 PRINT "The password is: word" 0030 PRINT 0040 PRINT "Enter the password:" 0050 FOR x:=1 TO 4 DO 0060 c$:=inkey$ 0070 password$:+c$ 0080 PRINT ".", 0090 ENDFOR x 0100 IF password$<>"word" THEN 0110 PRINT "Nope." 0120 ELSE 0130 PRINT "You pass." 0140 ENDIF 0150 END "Done" 0010 page 0020 PRINT "INOUT is used with SELECT." 0030 PRINT "See the reference pages for SELECT." 0040 END "Done" 0010 page 0020 INPUT "What is your name: ": name$, 0030 PRINT "...Thank you." 0040 PRINT "Good bye,";name$ 0050 END "Done" 0010 DIM text$ OF 100 0020 page 0030 PRINT "INPUT FILE used only with ASCII files." 0040 PRINT "Here is the contents of the file" 0050 PRINT "INPUTFILE.LST" 0060 PRINT 0070 OPEN FILE 2,"inputfile.lst",READ 0080 WHILE NOT eof(2) DO 0090 INPUT FILE 2: text$ 0100 PRINT text$ 0110 ENDWHILE 0120 CLOSE FILE 2 0130 END "Done" 0010 page 0020 PRINT "INT ... 5 examples." 0025 PRINT "(include negative and decimals)" 0030 LOOP 5 TIMES 0040 INPUT "Number: ": num; 0050 PRINT "INT is";int(num) 0060 ENDLOOP 0070 END "Done" 0010 page 0020 PRINT "Press the key that is your" 0030 PRINT "favorite letter of the alphabet:" 0040 WAIT 0050 c$:=key$ 0060 PRINT "You pressed";c$ 0070 END "Done" 0010 page 0020 DIM weekday$(7) OF 10 0030 DATA "This will be ignored" 0040 DAYS: 0050 DATA "Sunday","Monday","Tuesday" 0060 DATA "Wednesday","Thursday","Friday" 0070 DATA "Saturday" 0080 RESTORE DAYS 0090 READ weekday$() //read data for EVERY item! 0100 PRINT "Data is read." 0110 FOR x:=1 TO 7 DO PRINT weekday$(x) 0120 END "Done" 0010 page 0020 PRINT "This is Len Lindsays favorite keyword" 0030 DIM text$ OF 100 0040 PRINT "Just hit to stop" 0050 LOOP 0060 PRINT "Type something on the next line." 0070 INPUT text$ 0080 EXIT WHEN text$="" 0090 PRINT "The length of" 0100 PRINT text$ 0110 PRINT "is";len(text$) 0120 ENDLOOP 0130 END "Done" 0010 page 0020 PRINT "LET is the assignment keyword." 0030 PRINT "It is rarely typed, and is not listed." 0040 count:=0 //initialize 0050 INPUT "What should count equal? ": count 0060 PRINT "Count now equals";count 0070 count:+2 0080 PRINT "Adding 2 makes it";count 0090 END "Done" 0010 page 0020 PRINT "LIST is the command used to" 0030 PRINT "list the program in memory." 0040 END "Done" 0010 page 0020 PRINT "LISTPACK is used to tell you" 0030 PRINT "what packages are available" 0040 PRINT "plus what commands are added" 0050 PRINT "by them. Example:" 0060 PRINT "USE SYSTEM" 0070 PRINT "LISTPACK <--- shows packages" 0080 PRINT "LISTPACK system" 0090 PRINT "xxxxx <--- lists keywords of SYSTEM" 0100 END "Done" 0010 page 0020 PRINT "LOAD is the command used to" 0030 PRINT "retrieve a COMAL program that" 0040 PRINT "was stored to disk via SAVE." 0050 PRINT 0060 PRINT "To get a useful File Requestor" 0070 PRINT "just type the command:" 0080 PRINT " LOAD" 0090 END "Done" 0010 page 0020 LOOP 0030 INPUT "Number (0=stop): ": num 0040 EXIT WHEN num=0 0050 PRINT "LOG of";num;"is";log(num) 0060 ENDLOOP 0070 END "Done" 0010 page 0020 LOOP 0030 TRAP 0040 INPUT "Enter your age: ": age 0050 EXIT WHEN age>=0 AND age<=110 0060 PRINT 0070 PRINT "age must be between 0 and 110" 0080 HANDLER 0090 PRINT 0100 PRINT "Numbers only for age." 0110 ENDTRAP 0120 ENDLOOP 0130 PRINT "You are";age;"years old." 0140 END "Done" 0010 page 0020 PRINT "MAIN is a command you use when" 0030 PRINT "a running program is stopped" 0040 PRINT "while it is inside an external" 0050 PRINT "procedure or function. It puts" 0060 PRINT "you back into the main program." 0070 END "Done" 0010 page 0020 PRINT "MAKEDIR is converted into MKDIR." 0030 PRINT "See MKDIR for info." 0040 END "Done" 0010 page 0020 DIM temperature(-40:120) 0030 PRINT "Enter the temperature outside" 0040 PRINT "for the past 7 days." 0050 PRINT "The range of accepted values is" 0060 min:=minindex(temperature()) 0070 max:=maxindex(temperature()) 0080 PRINT min;"to";max 0090 PRINT 0100 LOOP 7 TIMES 0110 LOOP 0120 PRINT AT 6,1: spc$(80) //clear line 0130 INPUT AT 6,1,3: "Enter temperature: ": degrees 0140 PRINT AT 8,1: degrees;"accepted. Thank you." 0150 EXIT WHEN degrees>=min AND degrees<=max 0160 PRINT AT 8,1: "Out of range. Try again." 0170 ENDLOOP 0180 temperature(degrees):+1 0190 ENDLOOP 0200 PRINT 0210 PRINT "Here are the temperatures" 0220 PRINT "and how many times recorded." 0230 PRINT 0240 FOR x:=min TO max DO 0250 IF temperature(x)>0 THEN PRINT x;temperature(x) 0260 ENDFOR x 0270 END "Done" 0010 page 0020 PRINT "MEMWINDOW ... use this command" 0030 PRINT "to display (or close) the" 0040 PRINT "small window showing memory free." 0050 PRINT 0060 PRINT "MEMWINDOW+" 0070 PRINT "opens the window. To close it:" 0080 PRINT "MEMWINDOW-" 0090 END "Done" 0010 page 0020 PRINT "MERGE is a command that allows" 0030 PRINT "you to merge program segments" 0040 PRINT "together into one program." 0050 END "Done" 0010 page 0020 DIM temperature(-40:120) 0030 PRINT "Enter the temperature outside" 0040 PRINT "for the past 7 days." 0050 PRINT "The range of accepted values is" 0060 min:=minindex(temperature()) 0070 max:=maxindex(temperature()) 0080 PRINT min;"to";max 0090 PRINT 0100 LOOP 7 TIMES 0110 LOOP 0120 PRINT AT 6,1: spc$(80) //clear line 0130 INPUT AT 6,1,3: "Enter temperature: ": degrees 0140 PRINT AT 8,1: degrees;"accepted. Thank you." 0150 EXIT WHEN degrees>=min AND degrees<=max 0160 PRINT AT 8,1: "Out of range. Try again." 0170 ENDLOOP 0180 temperature(degrees):+1 0190 ENDLOOP 0200 PRINT 0210 PRINT "Here are the temperatures" 0220 PRINT "and how many times recorded." 0230 PRINT 0240 FOR x:=min TO max DO 0250 IF temperature(x)>0 THEN PRINT x;temperature(x) 0260 ENDFOR x 0270 END "Done" 0010 page 0020 PRINT "This is your current directory:" 0030 PRINT dir$ 0040 PRINT 0050 PRINT "Now, we will create a" 0060 PRINT "new subdirectory!" 0070 PRINT 0080 name$:="z" 0090 LOOP 8 TIMES name$:+chr$(rnd(65,90)) 0100 PRINT "New directory is called:";name$ 0110 MKDIR name$ 0120 PRINT 0130 PRINT "Now we better get rid of it..." 0140 DELETE name$ 0150 PRINT 0160 PRINT "Gone." 0170 END "Done" 0010 page 0020 LOOP 0030 INPUT "Integer (0=stop): ": n1 0040 EXIT WHEN n1=0 0050 INPUT "Integer: ": n2 0060 ones:=n2 MOD 10 //get ones digit 0070 answer:=n1 DIV n2 0080 remainder:=n1 MOD n2 0090 IF n2=11 OR n2=12 OR n2=13 THEN 0100 ending$:="th" 0110 ELSE 0120 CASE ones OF 0130 WHEN 0,4,5,6,7,8,9 0140 ending$:="th" 0150 WHEN 1 0160 ending$:="st" 0170 WHEN 2 0180 ending$:="nd" 0190 WHEN 3 0200 ending$:="rd" 0210 OTHERWISE 0220 PRINT "ERROR" 0230 ENDCASE 0240 ENDIF 0250 IF remainder<>1 THEN ending$:+"s" //plural 0260 PRINT n1;"divided by";n2;"is";answer; 0270 IF remainder THEN PRINT "and";remainder,"/",n2,ending$; 0280 PRINT //carriage return 0290 ENDLOOP 0300 END "Done" 0010 page 0020 PRINT "NEW is a command that will clear" 0030 PRINT "the COMAL memory so you can begin" 0040 PRINT "a fresh new program. It will warn" 0050 PRINT "you if it is going to erase a" 0060 PRINT "current program that is not saved." 0070 END "Done" 0010 page 0020 PRINT "NEXT is converted to ENDFOR." 0030 END "Done" 0010 page 0020 WHILE NOT eod DO 0030 READ text$ 0040 PRINT text$ 0050 ENDWHILE 0060 DATA "one","two","three","go" 0070 END "Done" 0010 page 0020 PRINT "NULL does nothing!" 0030 INPUT "Type a digit: ": num 0040 CASE num OF 0050 WHEN 0 0060 PRINT "Zero" 0070 WHEN 1 0080 PRINT "One" 0090 OTHERWISE 0100 NULL // do nothing. 0110 ENDCASE 0120 PRINT "Thank you." 0130 END "Done" 0010 page 0020 infile:=freefile 0030 filename$:="visitor.dat" 0040 OPEN FILE infile,filename$,READ 0050 WHILE NOT eof(infile) DO 0060 READ FILE infile: text$ 0070 PRINT text$ 0080 ENDWHILE 0090 CLOSE FILE infile 0100 END "Done" 0010 page 0020 DIM letter$ OF 1 0030 REPEAT 0040 PRINT "Enter a CAPITAL letter (Q=Quit)" 0050 INPUT "-->": letter$; 0060 IF letter$<="A" OR letter$>="Z" THEN PRINT "NO"; 0070 PRINT //carriage return 0080 UNTIL letter$="Q" 0090 END "Done" 0010 page 0020 a:=ord("a"); z:=ord("z") 0030 DIM letters(a:z) 0040 INPUT "Word (in lower case): ": word$ 0050 FOR x:=1 TO len(word$) DO 0060 char:=ord(word$(x:x)) // substring of word$ 0070 letters(char):+1 // increment letter count 0080 ENDFOR 0090 FOR letter:=a TO z DO 0100 IF letters(letter) THEN 0110 PRINT "Letter:";chr$(letter); 0120 PRINT "occurances:";letters(letter) 0130 ENDIF 0140 ENDFOR 0150 END "Done" 0010 page 0020 DIM reply$ OF 1 0030 REPEAT 0040 INPUT "Good, bad or ugly (G,B,U): ": reply$; 0050 CASE reply$ OF 0060 WHEN "G","g" 0070 PRINT "Good bye" 0080 WHEN "B","b" 0090 PRINT "Bad" 0100 WHEN "U","u" 0110 PRINT "Ugly" 0120 OTHERWISE 0130 PRINT "Try again" 0140 ENDCASE 0150 UNTIL reply$ IN "Gg" 0160 END "Done" 0010 page 0020 PRINT "OUTPUT ... see SELECT OUTPUT" 0030 END "Done" 0010 page // clear screen 0020 DIM name$ OF 30, company$ OF 30, reply$ OF 1 0030 DATA "Robert Grimm","Universal Electronics",1 0040 DATA "Sam Thompson","Global Technology",3 0050 DATA "Paul Peterson","Modern Repairs",0 0060 // 0070 PRINT "Output to Screen or Printer? reply$" 0080 INPUT "(S,P): ": reply$ 0090 CASE reply$ OF 0100 WHEN "S","s" 0110 SELECT OUTPUT "ds:" 0120 WHEN "P","p" 0130 SELECT OUTPUT "lp:" 0140 OTHERWISE 0150 NULL //unknown request 0160 ENDCASE 0170 WHILE NOT eod DO 0180 page // clear screen OR page feed 0190 READ name$,company$,level 0200 PRINT name$ 0210 PRINT company$ 0220 PRINT "Level:";level 0230 PRINT "(0=Technician 1=Engineer 2=V.P. 3=President" 0240 INPUT "Hit for next name": reply$ 0250 ENDWHILE 0260 SELECT OUTPUT "ds:" //return output to screen 0270 END "Done" 0010 page 0020 PRINT "Now lets issue a DOS command." 0030 PASS "DIR" 0040 END "Done" 0010 page 0020 LOOP 0030 INPUT "Radius of circle (0=stop): ": radius 0040 EXIT WHEN radius=0 0050 PRINT "Circle area is";pi*(radius^2) 0060 ENDLOOP 0070 END "Done" 0010 page 0020 PRINT "POINTER ... see Chapter 3.6." 0030 END "Done" 0010 page 0020 DIM word$ OF 20 0030 word$:="Variables"; money:=25.6 0040 PRINT TAB(5),"Constants and";word$ 0050 PRINT USING "Total due $###.## ": money 0060 PRINT // blank line 0070 PRINT AT 9,6: "End of this." 0080 END "Done" 0010 page 0020 PRINT "Now we will log the current" 0030 PRINT "time and date to disk file" 0040 PRINT "named datetime.log" 0050 PRINT 0060 f:=freefile // file number 0070 OPEN FILE f,"datetime.log",APPEND 0080 PRINT FILE f: date$;time$ 0090 CLOSE FILE f 0091 PRINT "Here is the log so far:" 0092 OPEN FILE f,"datetime.log",READ 0093 WHILE NOT eof(f) DO 0094 INPUT FILE f: text$ 0095 PRINT text$ 0096 ENDWHILE 0097 CLOSE FILE f 0100 END "Done" 0010 page 0020 LOOP 0030 INPUT "Word (Q=Quit): ": word$, 0040 EXIT WHEN word$ IN "Qq" 0050 backwards(word$) 0060 ENDLOOP 0070 END "Done" 0080 // 0090 PROC backwards(a$) CLOSED 0100 PRINT "...", 0110 FOR temp:=len(a$) TO 1 STEP -1 DO PRINT a$(temp:temp), 0120 PRINT // carriage return 0130 ENDPROC backwards 0010 page 0020 DIM item$ OF 80 0030 TRAP 0040 ran'file:=freefile 0050 OPEN FILE ran'file,"test.ran",RANDOM 82 0060 HANDLER 0070 PRINT errtext$ 0080 PRINT "Error opening the file." 0090 PRINT "Ending program now." 0100 CLOSE 0110 END "File error. Program ended." 0120 ENDTRAP 0130 LOOP 0140 TRAP 0150 PRINT "What record number (0=stop): " 0160 PRINT " <---", 0170 INPUT AT 0,1,2: "": number 0180 EXIT WHEN number=0 0190 IF number<0 THEN REPORT 900 0200 IF number>20 THEN REPORT 901 //limit records for this test 0210 HANDLER 0220 PRINT // new line 0230 CASE err OF 0240 WHEN 900 0250 PRINT "Negative record numbers are not allowed" 0260 WHEN 901 0270 PRINT "Only 20 records for this test." 0280 OTHERWISE 0290 PRINT "Enter a number from 1 - 20" 0300 ENDCASE 0310 RETRY 0320 ENDTRAP 0330 INPUT "Read or Write it? ": item$ 0340 CASE item$ OF 0350 WHEN "R","r","Read","READ","read" 0360 read'it 0370 WHEN "W","w","Write","WRITE","write" 0380 write'it 0390 OTHERWISE 0400 PRINT "No such option." 0410 ENDCASE 0420 ENDLOOP 0430 CLOSE 0440 END "Done" 0450 // 0460 PROC write'it 0470 page 0480 PRINT "Record number";number 0490 PRINT "Enter up to 80 characters to write:" 0500 INPUT "": item$ 0510 WRITE FILE ran'file,number: item$ 0520 PRINT AT 0,1: "OK" 0530 ENDPROC write'it 0540 // 0550 PROC read'it 0560 page 0570 PRINT "Record number";number 0580 READ FILE ran'file,number: item$ 0590 IF item$>"" THEN 0600 PRINT item$ 0610 ELSE 0620 PRINT "Nothing in the record." 0630 ENDIF 0640 PRINT 0650 ENDPROC read'it 0010 page 0020 heads:=0; tails:=0 //initialize 0030 RANDOMIZE 9 //<--- 9 specified gives SAME random sequence each time 0040 PRINT "This shows how you can CHEAT with RANDOMIZE" 0050 PRINT "by specifying a specific seed after RANDOMIZE." 0060 PRINT "Notice the results of the random flips are" 0070 PRINT "the same EVERY time." 0080 PRINT 0090 REPEAT 0100 flip:=rnd(0,1) 0110 IF flip=0 THEN 0120 PRINT "Heads" 0130 heads:+1 0140 ELSE 0150 PRINT "Tails" 0160 tails:+1 0170 ENDIF 0180 UNTIL heads>4 OR tails>4 0190 winner(heads,tails) // execute procedure 0200 END "Done" 0210 // 0220 PROC winner(h,t) CLOSED 0230 IF h>t THEN 0240 PRINT "The winner is HEADS." 0250 ELSE 0260 PRINT "The winner is TAILS." 0270 ENDIF 0280 ENDPROC winner 0010 page 0020 DIM month$(1:12) OF 3 0030 DATA "Jan","Feb","Mar","Apr","May","Jun" 0040 DATA "Jul","Aug","Sep","Oct","Nov","Dec" 0050 READ month$() // read all elements 0060 LOOP 0070 PRINT "Which month number (0=stop): " 0080 INPUT "--> ": num; 0090 EXIT WHEN num=0 0100 PRINT "..."; 0110 CASE num OF 0120 WHEN 11,12,1,2 0130 PRINT month$(num);"... cold" 0140 WHEN 6,7,8 0150 PRINT month$(num);"... hot" 0160 WHEN 3,4,5,9,10 0170 PRINT month$(num);"... nice" 0180 OTHERWISE 0190 PRINT "???" 0200 PRINT "I don't know a month with that number." 0210 ENDCASE 0220 ENDLOOP 0230 END "Done" 0010 page 0020 infile:=freefile 0030 filename$:="visitor.dat" 0040 OPEN FILE infile,filename$,READ 0050 WHILE NOT eof(infile) DO 0060 READ FILE infile: text$ 0070 PRINT text$ 0080 ENDWHILE 0090 CLOSE FILE infile 0100 END "Done" 0010 page 0020 PRINT "READWRITE is a type of file access." 0030 PRINT "It allows you to read or write to the file." 0040 END "Done" 0010 page 0020 PRINT "RECORD ... see Chapter 3.3." 0030 END "Done" 0010 page 0020 DIM junk$(3) OF 1 0030 junk$(1):="a"; junk$(2):="b"; junk$(3):="c" 0040 LOOP 0050 INPUT "Which junk? 1,2,3 (0=stop): ": which 0060 EXIT WHEN which=0 0070 CASE which OF 0080 WHEN 1,2,3 0090 see(which,junk$()) 0100 OTHERWISE 0110 PRINT "No such junk." 0120 ENDCASE 0130 PRINT 0140 PRINT "Junk now set at:" 0150 FOR x:=1 TO 3 DO PRINT x;junk$(x) 0160 PRINT 0170 ENDLOOP 0180 END "Done" 0190 // 0200 PROC see(num,REF a$()) CLOSED 0210 PRINT "Junk number";num;"is";a$(num) 0220 PRINT "Changing it inside this CLOSED proc now." 0230 a$(num):=chr$(rnd(ord("d"),ord("z"))) 0240 PRINT "Now it is";a$(num) 0250 ENDPROC see 0010 page 0020 PRINT "RENAME will rename a file." 0030 END "Done" 0010 page 0020 PRINT "RENUM will renumber the program lines." 0030 END "Done" 0010 page 0020 number:=rnd(1,10) 0030 REPEAT 0040 INPUT "Guess the number (1-10): ": guess 0050 IF guess>number THEN PRINT "Too high." 0060 IF guess120 THEN REPORT nonsense 0100 HANDLER 0110 PRINT 0120 IF err=input'error THEN 0130 REPORT nonsense // drop to outer handler 0140 ELSE 0150 REPORT // system error 0160 ENDIF 0170 ENDTRAP 0180 PRINT "Welcome to COMAL,";name$ 0190 HANDLER 0200 IF err=nonsense THEN 0210 PRINT 0220 PRINT "Please pay attention." 0230 PRINT "Enter your name and age." 0240 PRINT // blank line 0250 RETRY 0260 ELSE 0270 REPORT // let system handle other errors 0280 ENDIF 0290 ENDTRAP 0300 END "Done" 0010 page 0020 DATA 1,3,2,1 // this is the combination 0030 PRINT "Try to open the safe." 0040 PRINT "Enter all the digits correctly." 0050 PRINT "(0=stop)" 0060 digit:=0 // initialize 0070 REPEAT 0080 digit:+1 // increment digit 0090 READ solution // correct code for this digit 0100 IF digit=1 THEN PRINT 20*"-" // a line 0110 PRINT digit, 0120 INPUT "> Enter digit: ": guess; 0130 IF guess=solution THEN 0140 PRINT "right" 0150 ELSE 0160 PRINT "ooops" 0170 RESTORE // reset data pointer 0180 digit:=0 // reset digit number 0190 ENDIF 0200 UNTIL eod OR guess=0 0210 IF eod THEN PRINT "You got it!" 0220 END "Done" 0010 page 0020 INPUT "Enter a number: ": num 0030 editnum(num) // call the proc 0040 PRINT // blank line 0050 PRINT "The number now is";num 0060 END "Done" 0070 // 0080 PROC editnum(REF number) CLOSED 0090 row:=currow; col:=curcol 0100 TRAP 0110 t$:=str$(number) 0120 max:=len(t$) 0130 IF max<8 THEN max:=8 0140 PRINT "Edit the number now:" 0150 PRINT t$,spc$(20), // , means stay on line 0160 INPUT AT 0,1,max: "": number 0170 HANDLER 0180 PRINT chr$(7) // bell 0190 CURSOR row,col 0200 RETRY 0210 ENDTRAP 0220 ENDPROC editnum 0010 page 0020 DIM type$(0:1) OF 4 0030 type$(true):="Even"; type$(false):="Odd" 0040 REPEAT 0050 INPUT "What number (0=stop): ": number; 0060 PRINT type$(even(number)) //function even called 0070 UNTIL number=0 0080 END "Done" 0090 // 0100 FUNC even(num) CLOSED 0110 IF num MOD 2 THEN RETURN false 0120 RETURN true // odd numbers exited already 0130 ENDFUNC even 0010 page 0020 DIM roll$ OF 1 0030 RANDOMIZE // optional 0040 PRINT "Roll two dice till you get 7." 0050 PRINT 35*"-" //line 0060 PRINT "Press R to roll the dice each time." 0070 REPEAT 0080 REPEAT 0090 roll$:=inkey$ 0100 UNTIL roll$ IN "Rr" 0110 dice1:=rnd(1,6) 0120 dice2:=rnd(1,6) 0130 PRINT "Roll was";dice1;dice2 0140 UNTIL dice1+dice2=7 0150 PRINT "Great ... 7 ... you got it." 0160 END "Done" 0010 page 0020 bug:=false 0030 PRINT "ROUND testing...15 random tries." 0040 PRINT 0050 LOOP 15 TIMES 0060 r:=rnd // random number between 0 and 1 0070 r:=r*200 // wider range 0080 r:-100 // get possible negative num 0090 PRINT USING "Number=-##.#### Round=-##.####": r,round(r) 0100 IF round(r)<-100 THEN bug:=true 0110 ENDLOOP 0120 IF bug THEN PRINT "We reported the ROUND bug already." 0130 END "Done" 0010 page 0020 PRINT "RUN is the command used to" 0030 PRINT "start program execution." 0040 END "Done" 0010 page 0020 PRINT "RUNWINDOW is the command to" 0030 PRINT "combine the Execute and Command" 0040 PRINT "Windows." 0050 END "Done" 0010 page 0020 PRINT "SAVE will store the current" 0030 PRINT "program in memory to disk." 0040 PRINT "It can be retrieved with" 0050 PRINT "LOAD, CHAIN, or RUN." 0060 PRINT 0070 PRINT "To get a File Requestor," 0080 PRINT "just issue the command:" 0090 PRINT " SAVE" 0100 END "Done" 0010 page 0020 PRINT "SCAN will check over the current" 0030 PRINT "program in memory for structure" 0040 PRINT "errors." 0050 END "Done" 0010 page 0020 DIM reply$ OF 1 0030 DATA "Jim","Sue","Fred","Rhianon" 0040 DATA "Charly","Steve" 0050 PRINT "Reply Y to print name on printer." 0060 REPEAT 0070 READ name$ 0080 PRINT name$ 0090 INPUT reply$ 0100 IF reply$ IN "Yy" THEN 0110 SELECT OUTPUT "lp:" //printer 0120 PRINT name$ 0130 SELECT OUTPUT "ds:" // back to screen 0140 ENDIF 0150 UNTIL eod 0160 END "Done" 0010 page 0020 DIM type$(-1:1) OF 10 0030 type$(-1):="Negative" 0040 type$(0):="Zero" 0050 type$(1):="Positive" 0060 PRINT "Here are sample SGN tests:" 0070 LOOP 15 TIMES 0080 num:=rnd(-5,5) 0090 PRINT num;TAB(4),type$(sgn(num)) 0100 ENDLOOP 0110 END "Done" 0010 page 0020 LOOP 0030 INPUT "Number (0=stop): ": num 0040 EXIT WHEN num=0 0050 PRINT "Sine of";num;"is";sin(num) 0060 ENDLOOP 0070 END "Done" 0010 page 0020 PRINT "SIZE is a command that reports" 0030 PRINT "on the size of your program, data" 0040 PRINT "area and the free memory avaiable" 0050 PRINT "to you for COMAL programs." 0060 END "Done" 0010 page 0020 PRINT "Enter 0 to stop." 0030 LOOP 0040 INPUT "How much space between words? ": space 0050 EXIT WHEN space=0 0060 PRINT " 1 1 2 2 3" 0070 PRINT "----5----0----5----0----5----0" 0080 PRINT "Yes",spc$(space),"No",spc$(space),"Maybe" 0090 ENDLOOP 0100 END "Done" 0010 page 0020 number'total:=0; sqr'total:=0; count:=0 0030 LOOP 0040 INPUT "Number (0=stop): ": number 0050 EXIT WHEN number=0 0060 number'total:+number // add number to total 0070 count:+1 // increment count 0080 sqr'total:+sqr(number) // add sqr to total 0090 PRINT "The square root is";sqr(number) 0100 ENDLOOP 0110 PRINT count;"numbers totaling";number'total 0120 PRINT "Total of their square roots is";sqr'total 0130 PRINT "The square root of their total is";sqr(number'total) 0140 END "Done" 0010 page 0020 PRINT "STEP can be used as a command" 0030 PRINT "to single step TRACE." 0040 PRINT 0050 PRINT "It also is used with a FOR loop:" 0060 PRINT 0070 LOOP 0080 INPUT "What number to count by (0=stop): ": num 0090 EXIT WHEN num=0 0100 FOR count:=num TO num*6 STEP num DO PRINT count; 0110 PRINT "How was that?" 0120 ENDLOOP 0130 END "Done" 0010 page 0020 temp:=5 0030 PRINT "TEMP is now";temp 0040 STOP "Change TEMP then issue CON command." 0050 PRINT "You changed TEMP to";temp 0060 END "Done" 0010 page 0020 REPEAT 0030 INPUT "Number (0=stop): ": num; 0040 PRINT str$(num) 0050 UNTIL num=0 0060 END "Done" 0010 page 0020 LOOP 0030 INPUT "What column (0=stop): ": col 0040 EXIT WHEN col=0 0050 PRINT "1---5----0----5----0----5----0" 0060 PRINT TAB(col),"*" 0070 ENDLOOP 0080 END "Done" 0010 page 0020 LOOP 0030 INPUT "Enter angle (0=stop): ": num 0040 EXIT WHEN num=0 0050 PRINT "Tangent of";num;"is";tan(num) 0060 ENDLOOP 0070 END "Done" 0010 page 0020 LOOP 5 TIMES 0030 n:=rnd(1,99) 0035 PRINT n 0040 IF even(n) THEN 0050 PRINT n;"is even" 0060 ELSE 0070 PRINT n;"is odd" 0080 ENDIF 0090 ENDLOOP 0100 END "Done" 0110 // 0120 FUNC even(n) EXTERNAL "even" 0010 page 0020 DIM type$ OF 1 0030 total:=0 // initialize 0040 PRINT "Hit + for ADD or - for SUBTRACT." 0050 PRINT "Hit Q to Quit." 0060 PRINT 0070 REPEAT 0080 num1:=rnd(1,9); num2:=rnd(0,num1) //num2 never larger 0090 PRINT num1; 0100 INPUT "": type$; //"" prompt avoids the ? prompt 0110 IF type$ IN "+-" THEN 0120 PRINT num2;"="; 0130 IF type$="+" THEN 0140 PRINT num1+num2 0150 ELSE 0160 PRINT num1-num2 0170 ENDIF 0180 ELIF NOT (type$ IN "Qq") THEN 0190 PRINT "Enter + or - or Q to Quit" 0200 ENDIF 0210 UNTIL type$ IN "Qq" 0220 END "Done 0010 page 0020 PRINT "Press any key to stop." 0030 PRINT "This should keep correct time." 0040 REPEAT 0050 PRINT AT 5,5: time$ 0060 UNTIL key$>"" 0070 END "Done" 0010 page 0020 PRINT "The timer is now:";timer 0030 PRINT "Now I will set it to 0" 0040 TIMER 0 0050 PRINT "Timer is now:";timer 0060 END "Done" 0010 page 0020 INPUT "How many scores? ": max 0030 total:=0 // initialize 0040 FOR temp:=1 TO max DO 0050 PRINT "Score";temp; 0060 INPUT score 0070 total:+score 0080 ENDFOR temp 0090 PRINT "Total was";total,". Average was";total/max 0100 END "Done" 0010 page 0020 PRINT "TRACE is a command to help" 0030 PRINT "debug programs. See TRACE in" 0040 PRINT "the reference section of the" 0050 PRINT "manual." 0060 END "Done" 0010 page 0020 TRAP 0030 INPUT "Enter age: ": age 0040 IF age<0 OR age>110 THEN REPORT 888 0050 HANDLER 0060 IF err=888 THEN 0070 PRINT "Be reasonable." 0080 ELSE 0090 PRINT "-";errtext$(err)(6:) //substring 0100 PRINT "Enter number of years." 0110 ENDIF 0120 RETRY 0130 ENDTRAP 0140 PRINT "Age is";age 0150 END "Done" 0010 page 0020 TRAP ESC- // disable break keys!! 0030 PRINT "Press + to stop this." 0040 PRINT // blank line 0050 REPEAT 0060 WAIT 0070 UNTIL esc 0080 PRINT "Thank you." 0090 TRAP ESC+ // enable the break keys. 0100 END "Done" 0010 page 0020 done:=false // init 0030 total:=0 // init 0040 REPEAT 0050 INPUT "Number (0=stop): ": num 0060 total:+num // add to total 0070 IF num=0 THEN done:=true 0080 UNTIL done 0090 PRINT "Total was";total 0100 END "Done" 0010 page 0020 PRINT "Assigning a new UNIT with the" 0030 PRINT "UNIT command is converted" 0040 PRINT "into a CHDIR command. You also" 0050 PRINT "can use UNIT$ like DIR$ to get" 0060 PRINT "the current unit." 0070 PRINT 0080 current$:=unit$ 0090 PRINT "Current unit is";unit$ 0100 PRINT "Changing it to the ram drive." 0110 CHDIR "ram:" 0120 PRINT "Now the current unit is";unit$ 0130 PRINT 0140 PRINT "Putting it back the way it was..." 0150 CHDIR current$ 0160 END "Done" 0010 page 0020 total:=0 // init 0030 REPEAT 0040 INPUT "Go past 100 - Enter number: ": num 0050 total:+num 0060 UNTIL total>100 0070 PRINT "You just broke 100." 0080 PRINT "Your total was";total 0090 END "Done" 0010 USE TYPE // it is in the :packages directory 0020 page 0030 PRINT "Here is the listing of this program:" 0040 PRINT 0050 type("use.lst") 0060 END "Done" 0010 page 0020 DIM money$ OF 40 0030 money$:="In dollars up to 999.99: $-###.##" 0040 REPEAT 0050 INPUT "Enter amount (0=stop): ": amount 0060 PRINT USING money$: amount 0070 UNTIL amount=0 0080 END "Done" 0010 page 0020 DIM text$ OF 20 0030 PRINT "Enter some numbers to test VAL." 0040 PRINT "Watch the results." 0050 PRINT 0060 REPEAT 0070 INPUT "Number (0=stop): ": text$ 0080 PRINT val(text$) 0090 UNTIL text$="0" 0100 END "Done" 0010 page 0020 x:=0 0030 s$:="anything" 0040 DIM table(10,10) 0050 PRINT varsize(x);"size of x variable area" 0060 PRINT varsize(s$);"size of s$ variable area" 0070 PRINT varsize(table(,));"size of table array area" 0010 WAIT 1 // wait one second for execute window to initialize 0020 page 0030 PRINT "starting" 0040 starting:=timer 0050 LOOP 10000 TIMES x:=10/3 0060 PRINT USING "Time used: ##.##": timer-starting 0070 END "Done" 0010 page 0020 DIM choice$ OF 1 0030 LOOP 0040 INPUT "Enter a vowel (Q=Quit): ": choice$; 0050 EXIT WHEN choice$ IN "Qq" 0060 CASE choice$ OF 0070 WHEN "A","a","E","e","I","i","O","o","U","u" 0080 PRINT "Yes" 0090 OTHERWISE 0100 PRINT "Nope" 0110 ENDCASE 0120 ENDLOOP 0130 END "Done" 0010 page 0020 yes:=0; errors:=0; maxerrors:=2 // init 0030 PRINT "You are allowed";maxerrors;"error", 0040 IF maxerrors<>1 THEN PRINT "s", 0050 PRINT "." 0060 WHILE errors1 THEN PRINT "s", 0210 PRINT " after";yes;"right." 0220 END "Done" 0010 page 0020 PRINT "WRITE FILE can write the contents" 0030 PRINT "of an entire array at one time." 0040 PRINT 0050 DIM table1(3,3) 0060 DIM table2(3,3) 0070 DIM newtable(3,3) 0080 FOR x:=1 TO 3 DO 0090 FOR y:=1 TO 3 DO 0100 table1(x,y):=x+y 0110 table2(x,y):=x*y 0120 ENDFOR y 0130 ENDFOR x 0140 PRINT "Two tables are initialized." 0150 PRINT 0160 PRINT "Writing them to disk:" 0170 filename1$:="table1.dat" 0180 f:=freefile 0190 OPEN FILE f,filename1$,WRITE 0200 WRITE FILE f: table1(,) 0210 CLOSE FILE f 0220 filename2$:="table2.dat" 0230 OPEN FILE f,filename2$,WRITE 0240 WRITE FILE f: table2(,) 0250 CLOSE FILE f 0260 PRINT "Table values stored to disk." 0270 PRINT 0280 REPEAT 0290 PRINT "Which do you want to retrieve" 0300 INPUT "+ or * ---> ": reply$ 0310 UNTIL reply$ IN "*+" 0320 CASE reply$ OF 0330 WHEN "*" 0340 OPEN FILE f,filename2$,READ 0350 WHEN "+" 0360 OPEN FILE f,filename1$,READ 0370 OTHERWISE 0380 NULL 0390 ENDCASE 0400 READ FILE f: newtable(,) 0410 CLOSE FILE f 0420 PRINT "Newtable is initialized." 0430 PRINT 0440 FOR x:=1 TO 3 DO 0450 FOR y:=1 TO 3 DO PRINT newtable(x,y); 0460 PRINT //new line 0470 ENDFOR x 0480 END "Done" 0010 page 0020 DIM account$ OF 20 0030 count:=0 0040 PRINT "We will now write an" 0050 PRINT "account name file." 0060 PRINT "It could be used later" 0070 PRINT "to expand coded accounts." 0080 PRINT 0090 f:=freefile 0100 OPEN FILE f,"accountnames.dat",WRITE 0110 WHILE NOT eod DO 0120 READ account$ // from data statements 0130 count:+1 // next account number 0140 WRITE FILE f: account$ 0150 PRINT "Account number";count;"-";account$ 0160 ENDWHILE 0170 CLOSE FILE f 0180 END "Done" 0190 DATA "Office supplies","Postage and shipping" 0200 DATA "Professional fees","Advertising" 0010 page 0020 startzone:=zone // remember current zone setting 0030 PRINT "Current zone:";startzone, 0040 PRINT ". Increasing zones..." 0050 FOR temp:=0 TO 9 DO 0060 ZONE temp 0070 PRINT temp;"B";"Cc";"D" 0080 ENDFOR temp 0090 PRINT "Note: zone 1 and 2 are nearly alike." 0100 PRINT 0110 PRINT "The top three players in each game." 0120 PRINT 0130 ZONE 10 0140 PRINT "Game";"First";"Second";"Third" 0150 PRINT "----";"-----";"------";"-----" 0160 PRINT 1;"Rhianon";"Sue";"Pam" 0170 PRINT 2;"Pam";"Tom";"Richard" 0180 PRINT 3;"Sue";"Timothy";"Rhianon" 0190 PRINT 4;"Richard";"Rhianon";"Timothy" 0200 ZONE startzone // back to original 0210 END "Done"